import Vue from 'vue'
var VueComponent = {};
var base_url = '/helsinki/admin/';
var perPage = 20;

Vue.component('vue-pagination', {
    template: '#vue_pagination_template',
    data: function() {
        return {
            loading: true,
        };
    },
    props: {
        page: {
            type: Number,
            required: true,
        },
        size: {
            type: Number,
            required: true,
        },
        getNextFun: {
            type: Function,
            required: true,
        }
    },
    computed: {
        total_page: function() {
            return Math.ceil(this.size / perPage) || 1;
        }
    },
    ready: function() {
        this.loading = false;
    },
    methods: {
        getNextData: function(page) {
            console.log(page);
            this.getNext(page);
        },
        getNext: function(page) {
            this.getNextFun && this.getNextFun(page);
        }
    }
});

/*删除组件  2017.09.23 begin*/
Vue.component('vue-delete',{
	template:'#vue_delete_template',
	data(){
			return{
				modal1:false
			}
		},
		props:{
			id:{
				type:Number,
				required: true,
			},
			port:{
				type:String,
				required:true,
			},
			getThatFun:{
				type: Function,
	            required: true,
	        }
		},

		methods:{
			ok(){
				var _self = this;
				var id = _self.id
				this.$http.post('/api/laocai/sys/account/delete',{
					id: id
				}).then((res)=>{
					if(res.body.code == 0) {
						// console.log(res)
						_self.$Message.info('删除成功');
						this.getManagers();
					} else {
						alert(res.body.message);
					}

				});
			},
			cancel(){
				this.$Message.info('Clicked cancel');
			}
		}
})
/*删除组件  2017.09.23 end*/

Vue.component('vue-changepass',{
	template:'#vue_change_password',
	data(){
		return{
			modal2:false,
			nePass:'',
		}
	},
	props:{
		id:{
			type:Number,
			required: true,
		},
		type:{
			type:String,
			required: true,
		},
		port:{
			type:String,
			required:true,
		},
		getThatFun:{
			type: Function,
            required: true,
        }
	},
	methods:{
		ok(){
			var _self = this;
			var param = {};
			param.id = _self.id;
			param.roleName = _self.roleName;
			param.password = _self.nePass;
			this.$http.post('/api/laocai/sys/account/update',param).then((res)=>{
				if(res.body.code == 0) {
					// console.log(res)
					_self.$Message.success('修改成功');
					this.getVersion()
				} else {
					alert(res.body.message);
				}

			});
		},
		cancel(){
			this.$Message.info('Clicked cancel');
		}
	}
})

//弹窗
Vue.component('vue-description',{
	template:'#vue_description',
	data(){
		return{
			modal4:false,
			nePass:'',
		}
	},
	props:{
		id:{
			type:Number,
			required: true,
		},
		port:{
			type:String,
			required:true,
		},
		content:{
			type:String,
			required:true,
		},
		getThatFun:{
			type: Function,
            required: true,
        }
	},
	methods:{
		ok(){
			var _self = this;
			var param = {};
			param.id = _self.id;
			$.post(base_url + _self.port,param,function(res) {
				if (res.errcode == 0) {
					_self.$Message.info(res.data.info);
					_self.getThatFun(1);
				} else {
					_self.$Message.info(res.data.info);
				}
			});
		},
		cancel(){
			this.$Message.info('Clicked cancel');
		}
	}
})

